/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package shaman.storage.impl.util;

import java.io.ObjectInputStream;
import java.util.Iterator;

/**
 *
 * @author dmitriy
 */
public class ObjectStreamIterable<T> implements Iterable<T> {

    protected ObjectInputStream oi;
    private final Class<? extends T> ocl;
    private boolean iterating=false;

    public ObjectStreamIterable(ObjectInputStream oi, Class<? extends T> ocl) {
        this.oi = oi;
        this.ocl = ocl;
    }

    public synchronized Iterator<T> iterator() {
        if (iterating)
            throw new IllegalStateException("Only one iterator is allowed");
        return new ObjectStreamIterator<T>(oi, ocl);
    }


}
